<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/

if ($_GET[type]=='1')
{
$newstype='新闻';
$keynews='news_new_Increase';
}elseif($_GET[type]=='2')
{
$newstype='图片新闻';
$keynews='news_pic_new_Increase';
}elseif($_GET[type]=='3')
{
$newstype='公告';
$keynews='news_cement_Increase';
}elseif($_GET[type]=='4')
{
$newstype='通知';
$keynews='news_notice_Increase';
}elseif($_GET[type]=='5')
{
$newstype='大事记';
$keynews='news_chronicle_Increase';
}elseif($_GET[type]=='6')
{
$newstype='电子期刊';
$keynews='news_periodical_Increase';
}

get_config_keytable($keynews);
empty($do) && $do = 'list';
if ($do == 'list') {
	include_once('template/add.php');

} elseif ($do == 'save') {
	
	$savetype = getGP('savetype','P');
	$category = getGP('category','P');
	if(getGP('shownamemaster','P')!=''){
	$receive = getGP('shownamemaster','P');
	}else{
	$receive ='0';
	}
	$subject = getGP('subject','P');
	$content = getGP('content','P');
	$appendix = getGP('appendix','P');
	$type = getGP('type','P');
	$date=get_date('Y-m-d H:i:s',PHP_TIME);
	$uid=$_USER->id;
	if($type=='2'){
	$pic = getGP('pic','P');
	}else{
	$pic='0';
	}
	//主表信息
	$news = array(
		'category' => $category,
		'receive' => $receive,
		'subject' => $subject,
		'content' => $content,
		'appendix' => $appendix,
		'type' => $type,
		'date' => $date,
		'pic' => $pic,
		'uid' => $uid
	);
	//写入主表信息
	insert_db('news',$news);
	$id=$db->insert_id();
	if(getGP('shownamemasterid','P')!=''){
	$shownamemaster=explode(',',getGP('shownamemasterid','P')); 
	for($i=0;$i<sizeof($shownamemaster);$i++)
	{
	$news_read = array(
		'disdate' => $date,
		'uid' => $shownamemaster[$i],
		'dkey' => '0',
		'newsid'=>$id
	);
	insert_db('news_read',$news_read);
	}
	}
	
	if(getGP('sms_info_box_shownamemaster','P')!=''){
	$content='您有一个新'.$newstype.'需要阅读,请点击查看!<a href="admin.php?ac=views&fileurl=news&id='.$id.'&type='.$type.'&muid='.$_GET[muid].'">点击阅读>></a>';
	//接收人；内容；类型（1：有返回回值;0：无返回值）;URL
	SMS_ADD_POST($receive,$content,0,0,$_USER->id);
	}
	//手机短信
	if(getGP('sms_phone_box_shownamemaster','P')!=''){
	$content='您有一个新'.$newstype.'需要阅读;请登录OA进行阅读!';
	PHONE_ADD_POST(getGP('shownamemasterphone','P'),$content,$receive,0,0,$_USER->id);
	}
	
	$content=$category.get_inc_log(1).$receive.get_inc_log(1).$subject.get_inc_log(1).$content.get_inc_log(1).$appendix.get_inc_log(1).$type.get_inc_log(1).$pic;
	$title='新增'.$newstype.'信息';
	get_oa_log_dbadd($id,$content,$title,13,$_USER->id);
    goto_page('admin.php?ac=index&fileurl=news&type='.$type.'&muid='.$_GET[muid].'');

}

function get_news_type($selid = 0,$type=0) {
	global $db;
	$html = '';
	$sql = "SELECT nid,ntitle FROM ".DB_TABLEPRE."news_type where ntype='".$type."'";
	$query = $db->query($sql);
	while ($row = $db->fetch_array($query)) {
		$selstr = $row['nid'] == $selid ? 'selected="selected"' : '';
		$html .= '<option value="'.$row['nid'].'" '.$selstr.' >'.$row['ntitle'].'</option>';
	}
	return $html;
}


?>